package com.ktgj.pay.utils;


import org.apache.ibatis.type.Alias;
import org.apache.log4j.Logger;

import javax.mail.MessagingException;

@Alias("Log4js")
public class Log4j {

	private static final Logger LOGGER = Logger.getLogger(Log4j.class);
//	public static void main(String[] args){
//		
//		//logger1
//		LOGGER.trace("我是logger1，trace");
//		LOGGER.debug("我是logger1，debug");
//		LOGGER.info("我是logger1，info");
//		LOGGER.warn("我是logger1，warn");
//	       LOGGER.error("我是logger1，error");
//	       LOGGER.fatal("我是logger1，fatal");
////	       logger1.debug(args);
//		
//	}
	
	
	/**
	 * 记录日常日志
	 * @param requestXml
	 * @param responseXml
	 */
	public static void addLog(String methodName,String requestXml,String responseXml){
//		PropertyConfigurator.configure("\\src\\log4j.properties");
		String Log = "";
		String time = BaseUtil.getDateString("yyyyMMdd hh:mm:ss");
		Log = Log + "-----------------------方法名："+methodName+"-----------------------\n";
		Log = Log + "-----------------------请求参数XML-----------------------\n";
		Log = Log + requestXml+"\n";
		Log = Log + "-----------------------返回参数XML-----------------------\n";
		Log = Log + responseXml+"\n";
		Log = Log + "-----------------------日志记录结束---"+time+"-----------------------\n";
		LOGGER.info(Log);
//		try {
//			MailUtil.sendLogMail(Log);
//		} catch (MessagingException e) {
//			e.printStackTrace();
//			addErrorLog(e.getMessage(),"发送邮件错误日志");
//		}
		
	}
	
	/**
	 * 记录异常日志
	 * @param error
	 * @param methodName
	 */
	public static void addErrorLog(String error,String methodName){
//		PropertyConfigurator.configure("\\src\\log4j.properties");
//		String prefix =  getServletContext().getRealPath("/");
		String Log = "";
		String time = BaseUtil.getDateString("yyyyMMdd hh:mm:ss");
		Log = Log + "-----------------------方法名："+methodName+"-----------------------\n";
		Log = Log + "-----------------------错误输出-----------------------\n";
		Log = Log + error+"\n";
		Log = Log + "-----------------------日志记录结束---"+time+"-----------------------\n";
		LOGGER.error(Log);
		try {
			MailUtil.sendLogMail(Log);
		} catch (MessagingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
//			addErrorLog(e.getMessage(),"发送邮件错误日志");
		}
	}
	

	
	
}
